package com.jml.api.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MemberController {

	@Value("${server.port}")
	private String port;

	@Autowired
	private DiscoveryClient discoveryClient;

	@RequestMapping("/getMember")
	public String getMember() {
		return "this is zk getMember"+port;
	}


	@RequestMapping("/discoveryClientList")
	public List<ServiceInstance> discoveryClientList() {
		//得到该服务名字的全部注册信息
		List<ServiceInstance> instances = discoveryClient.getInstances("consul-provider");
		for (ServiceInstance serviceInstance: instances) {
			System.out.println("uri:"+serviceInstance.getUri());
		}
		return instances;
	}
}


